package org.epidroid.epidroid.epirss;

import java.util.List;

import org.epidroid.epidroid.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class RssListAdapter extends ArrayAdapter<RssArticle> {
	private List<RssArticle> items;
	private Context context;

	public RssListAdapter(Context context, int textViewResourceId, List<RssArticle> items) {
		super(context, textViewResourceId, items);
		this.items = items;
		this.context = context;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View v = convertView;
		if (v == null) {
			LayoutInflater vi = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			v = vi.inflate(R.layout.rss_articles_row, null);
		}
		RssArticle o = items.get(position);
		if (o != null) {
			TextView tt = (TextView) v.findViewById(R.id.tvTitle);
			TextView pt = (TextView) v.findViewById(R.id.tvPublished);
			if (tt != null) {
				tt.setText(o.title);
			}
			if(pt != null){
				pt.setText(o.published);
			}
		}
		return v;
	}
}
